﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Collections;
using System.Runtime.Serialization;
using System.Linq.Expressions;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;

namespace Suucha.Expressions
{
    /// <summary>
    /// SuuchaExpression抽象基类
    /// </summary>
#if SILVERLIGHT
    [DataContract]
#else
    [Serializable]
#endif
    [JsonConverter(typeof(ExpressionJsonConverter))]
    public abstract class SuuchaExpression
    {
        /// <summary>
        /// SuuchaExpression节点类型，参见<seealso cref="SuuchaExpressionType"/>。
        /// </summary>
        [DataMember]
        public virtual SuuchaExpressionType NodeType { get; set; }
        /// <summary>
        /// Suucha Expression And操作
        /// </summary>
        /// <param name="left">And操作的左边表达式</param>
        /// <param name="right">And操作的右边边表达式</param>
        /// <returns>返回一个SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression And(SuuchaBinaryExpression left, SuuchaBinaryExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.And;
            return bee;
        }
        /// <summary>
        /// 构建一个Or操作
        /// </summary>
        /// <param name="left">Or操作的左边表达式</param>
        /// <param name="right">Or操作的右边表达式</param>
        /// <returns>返回一个SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression Or(SuuchaBinaryExpression left, SuuchaBinaryExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.Or;
            return bee;
        }
        /// <summary>
        /// 创建一个成员表达式。
        /// </summary>
        /// <param name="name">成员名称，可以使用User.Name的形式</param>
        /// <returns>返回一个SuuchaMemberExpression，参见<seealso cref="SuuchaMemberExpression"/></returns>
        public static SuuchaMemberExpression Member(string name)
        {
            SuuchaMemberExpression me = new SuuchaMemberExpression();
            me.Name = name;
            return me;
        }
        /// <summary>
        /// 创建一个常数表达式
        /// </summary>
        /// <param name="value">常数值</param>
        /// <returns>返回一个SuuchaConstantExpression，参见<seealso cref="SuuchaConstantExpression"/></returns>
        public static SuuchaConstantExpression Constant(object value)
        {
            SuuchaConstantExpression ce = new SuuchaConstantExpression();
            ce.Value = value;
            return ce;
        }
        /// <summary>
        /// In操作
        /// </summary>
        /// <param name="left">In操作的左边表达式，必须是一个成员表达式</param>
        /// <param name="right">In操作的右边表达式，必须是一个用逗号分隔的字符串常量表达式</param>
        /// <returns>返回一个表示In操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression In(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.In;
            return bee;
        }
        /// <summary>
        /// In操作
        /// </summary>
        /// <param name="left">In操作的左边表达式，必须是一个成员名称</param>
        /// <param name="right">In操作的右边表达式，必须是一个用逗号分隔（如果有多个）的字符串</param>
        /// <returns>返回一个表示In操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression In(string left, string right)
        {
            return In(Member(left), Constant(right));
        }
        /// <summary>
        /// InLike操作
        /// </summary>
        /// <param name="left">InLike操作的左边表达式，必须是一个成员表达式</param>
        /// <param name="right">InLike操作的右边表达式，必须是一个用逗号分隔的字符串常量表达式</param>
        /// <returns>返回一个表示InLike操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression InLike(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.InLike;
            return bee;
        }
        /// <summary>
        /// InLike操作
        /// </summary>
        /// <param name="left">InLike操作的左边表达式，必须是一个成员名称</param>
        /// <param name="right">InLike操作的右边表达式，必须是一个用逗号分隔的字符串</param>
        /// <returns>返回一个表示InLike操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression InLike(string left, string right)
        {
            return InLike(Member(left), Constant(right));
        }
        /// <summary>
        /// 构建一个逻辑等于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression Equal(SuuchaMemberExpression left, SuuchaMemberExpression right)
        {
            return Equal((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个逻辑等于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression Equal(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            return Equal((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个逻辑等于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression Equal(SuuchaConstantExpression left, SuuchaConstantExpression right)
        {
            return Equal((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个逻辑等于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression Equal(SuuchaConstantExpression left, SuuchaMemberExpression right)
        {
            return Equal((SuuchaExpression)left, (SuuchaExpression)right);
        }

        private static SuuchaBinaryExpression Equal(SuuchaExpression left, SuuchaExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.Equal;
            return bee;
        }
        /// <summary>
        /// 构建一个逻辑等于操作
        /// </summary>
        /// <param name="left">左边表达式，成员名称</param>
        /// <param name="right">右边表达式，常量</param>
        /// <returns>返回一个表示判断等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression Equal(string left, object right)
        {
            return Equal(Member(left), Constant(right));
        }
        /// <summary>
        /// 构建一个大于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断大于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThan(SuuchaMemberExpression left, SuuchaMemberExpression right)
        {
            return GreaterThan((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个大于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断大于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThan(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            return GreaterThan((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个大于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断大于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThan(SuuchaConstantExpression left, SuuchaConstantExpression right)
        {
            return GreaterThan((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个大于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断大于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThan(SuuchaConstantExpression left, SuuchaMemberExpression right)
        {
            return GreaterThan((SuuchaExpression)left, (SuuchaExpression)right);
        }
        private static SuuchaBinaryExpression GreaterThan(SuuchaExpression left, SuuchaExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.GreaterThan;
            return bee;
        }
        /// <summary>
        /// 构建一个大于操作
        /// </summary>
        /// <param name="left">左边表达式，成员名称</param>
        /// <param name="right">右边表达式，常量</param>
        /// <returns>返回一个表示判断大于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThan(string left, object right)
        {
            return GreaterThan(Member(left), Constant(right));
        }
        /// <summary>
        /// 构建一个大于或等于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断大于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThanOrEqual(SuuchaMemberExpression left, SuuchaMemberExpression right)
        {
            return GreaterThanOrEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个大于或等于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断大于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThanOrEqual(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            return GreaterThanOrEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个大于或等于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断大于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThanOrEqual(SuuchaConstantExpression left, SuuchaConstantExpression right)
        {
            return GreaterThanOrEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个大于或等于操作
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断大于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThanOrEqual(SuuchaConstantExpression left, SuuchaMemberExpression right)
        {
            return GreaterThanOrEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        private static SuuchaBinaryExpression GreaterThanOrEqual(SuuchaExpression left, SuuchaExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.GreaterThanOrEqual;
            return bee;
        }
        /// <summary>
        /// 构建一个大于或等于操作
        /// </summary>
        /// <param name="left">左边表达式，成员名称</param>
        /// <param name="right">右边表达式，常量</param>
        /// <returns>返回一个表示判断大于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression GreaterThanOrEqual(string left, object right)
        {
            return GreaterThanOrEqual(Member(left), Constant(right));
        }
        /// <summary>
        /// 构建一个判断小于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断小于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThan(SuuchaMemberExpression left, SuuchaMemberExpression right)
        {
            return LessThan((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个判断小于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断小于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThan(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            return LessThan((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个判断小于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断小于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThan(SuuchaConstantExpression left, SuuchaConstantExpression right)
        {
            return LessThan((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个判断小于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断小于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThan(SuuchaConstantExpression left, SuuchaMemberExpression right)
        {
            return LessThan((SuuchaExpression)left, (SuuchaExpression)right);
        }
        private static SuuchaBinaryExpression LessThan(SuuchaExpression left, SuuchaExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.LessThan;
            return bee;
        }
        /// <summary>
        /// 构建一个判断小于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式，成员名称</param>
        /// <param name="right">右边表达式，常量</param>
        /// <returns>返回一个表示判断小于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThan(string left, object right)
        {
            return LessThan(Member(left), Constant(right));
        }
        /// <summary>
        /// 构建一个判断小于或等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断小于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThanOrEqual(SuuchaMemberExpression left, SuuchaMemberExpression right)
        {
            return LessThanOrEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个判断小于或等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断小于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThanOrEqual(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            return LessThanOrEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个判断小于或等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断小于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThanOrEqual(SuuchaConstantExpression left, SuuchaConstantExpression right)
        {
            return LessThanOrEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个判断小于或等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断小于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThanOrEqual(SuuchaConstantExpression left, SuuchaMemberExpression right)
        {
            return LessThanOrEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        private static SuuchaBinaryExpression LessThanOrEqual(SuuchaExpression left, SuuchaExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.LessThanOrEqual;
            return bee;
        }
        /// <summary>
        /// 构建一个判断小于或等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式，成员名称</param>
        /// <param name="right">右边表达式，常量</param>
        /// <returns>返回一个表示判断小于或等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression LessThanOrEqual(string left, object right)
        {
            return LessThanOrEqual(Member(left), Constant(right));
        }
        /// <summary>
        /// 构建一个判断不等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断不等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression NotEqual(SuuchaMemberExpression left, SuuchaMemberExpression right)
        {
            return NotEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个判断不等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断不等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression NotEqual(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            return NotEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个判断不等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断不等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression NotEqual(SuuchaConstantExpression left, SuuchaConstantExpression right)
        {
            return NotEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        /// <summary>
        /// 构建一个判断不等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式</param>
        /// <param name="right">右边表达式</param>
        /// <returns>返回一个表示判断不等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression NotEqual(SuuchaConstantExpression left, SuuchaMemberExpression right)
        {
            return NotEqual((SuuchaExpression)left, (SuuchaExpression)right);
        }
        private static SuuchaBinaryExpression NotEqual(SuuchaExpression left, SuuchaExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.NotEqual;
            return bee;
        }
        /// <summary>
        /// 构建一个判断不等于操作的表达式
        /// </summary>
        /// <param name="left">左边表达式，成员名称</param>
        /// <param name="right">右边表达式，常量</param>
        /// <returns>返回一个表示判断不等于操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression NotEqual(string left, object right)
        {
            return NotEqual(Member(left), Constant(right));
        }
        /// <summary>
        /// 构建一个判断Like操作的表达式
        /// </summary>
        /// <param name="left">左边表达式，成员表达式</param>
        /// <param name="right">右边表达式，用逗号分隔的字符串常量表达式</param>
        /// <returns>返回一个表示判断Like操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression Like(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.Like;
            return bee;
        }
        /// <summary>
        /// 构建一个判断Like操作的表达式
        /// </summary>
        /// <param name="left">左边表达式，成员名称</param>
        /// <param name="right">右边表达式，用逗号分隔的字符串</param>
        /// <returns>返回一个表示判断Like操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression Like(string left, string right)
        {
            return Like(Member(left), Constant(right));
        }
        /// <summary>
        /// 构建一个判断NotLike操作的表达式
        /// </summary>
        /// <param name="left">左边表达式，成员表达式</param>
        /// <param name="right">右边表达式，用逗号分隔的字符串常量表达式</param>
        /// <returns>返回一个表示判断NotLike操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression NotLike(SuuchaMemberExpression left, SuuchaConstantExpression right)
        {
            SuuchaBinaryExpression bee = new SuuchaBinaryExpression();
            bee.Left = left;
            bee.Right = right;
            bee.NodeType = SuuchaExpressionType.NotLike;
            return bee;
        }
        /// <summary>
        /// 构建一个判断NotLike操作的表达式
        /// </summary>
        /// <param name="left">左边表达式，成员名称</param>
        /// <param name="right">右边表达式，用逗号分隔的字符串</param>
        /// <returns>返回一个表示判断NotLike操作的SuuchaBinaryEXpression，参见<seealso cref="SuuchaBinaryExpression"/></returns>
        public static SuuchaBinaryExpression NotLike(string left, string right)
        {
            return NotLike(Member(left), Constant(right));
        }

        /// <summary>
        /// 从json字符串反序列化SuuchaExpression
        /// </summary>
        /// <param name="json">json字符串<seealso cref="String" /></param>
        /// <returns>
        ///   <seealso cref="SuuchaExpression" />
        /// </returns>
        public static SuuchaExpression FromJson(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return null;
            }
            return JsonConvert.DeserializeObject<SuuchaExpression>(json);
        }

    }

    /// <summary>
    /// 二元表达式
    /// </summary>
#if SILVERLIGHT
    [DataContract]
#else
    [Serializable]
#endif
    public  class SuuchaBinaryExpression : SuuchaExpression
    {
        /// <summary>
        /// 左边表达式
        /// </summary>
        [DataMember]
        public SuuchaExpression Left { get; set; }
        /// <summary>
        /// 右边表达式
        /// </summary>
        [DataMember]
        public SuuchaExpression Right { get; set; }
    }
    /// <summary>
    /// 常量表达式
    /// </summary>
#if SILVERLIGHT
    [DataContract]
#else
    [Serializable]
#endif
    public  class SuuchaConstantExpression : SuuchaExpression
    {

        /// <summary>
        /// 初始化类<see cref="SuuchaConstantExpression" />的一个新实例
        /// </summary>
        public SuuchaConstantExpression()
            : this(null)
        {
        }
        /// <summary>
        /// 初始化类<see cref="SuuchaConstantExpression" />的一个新实例
        /// </summary>
        /// <param name="value">常量值</param>
        public SuuchaConstantExpression(object value)
        {
            NodeType = SuuchaExpressionType.Constant;
            Value = value;
        }
        /// <summary>
        /// 常量值
        /// </summary>
        [DataMember]
        public object Value { get; set; }

    }
    /// <summary>
    /// 成员表达式
    /// </summary>
#if SILVERLIGHT
    [DataContract]
#else
    [Serializable]
#endif
    public class SuuchaMemberExpression : SuuchaExpression
    {
        /// <summary>
        /// 构造函数
        /// </summary>
        public SuuchaMemberExpression()
            : this("")
        {
        }
        /// <summary>
        /// 指定成员名称的构造函数
        /// </summary>
        /// <param name="name">成员名称</param>
        public SuuchaMemberExpression(string name)
        {
            NodeType = SuuchaExpressionType.Member;
            Name = name;
        }
        /// <summary>
        /// 成员名称，可以是User.Name这种方式
        /// </summary>
        /// <value>
        /// 成员名称
        /// </value>
        [DataMember]
        public string Name { get; set; }
    }

    /// <summary>
    /// 查询参数类
    /// </summary>
#if SILVERLIGHT
    [DataContract]
#else
    [Serializable]
#endif
    public class SearchParameters
    {
        private List<SuuchaOrderBy> sorts = new List<SuuchaOrderBy>();
        /// <summary>
        /// 设置或者获取查询条件
        /// </summary>
        /// <value>
        /// 查询条件
        /// </value>
        [DataMember]
        public SuuchaExpression Condition { get; set; }
        /// <summary>
        /// 设置或获取字段选择字符串
        /// </summary>
        /// <value>
        /// 字段选择
        /// </value>
        [DataMember]
        public string Selector { get; set; }

        /// <summary>
        /// 设置或获取排序列表
        /// </summary>
        /// <value>
        /// 排序列表
        /// </value>
        [DataMember]
        public List<SuuchaOrderBy> Sorts
        {
            get
            {
                if (sorts == null)
                {
                    sorts = new List<SuuchaOrderBy>();
                }
                return sorts;
            }
            set
            {
                sorts = value;
            }
        }
        /// <summary>
        /// 获取或者设置页码
        /// </summary>
        /// <value>
        /// 页码
        /// </value>
        [DataMember]
        public int Page { get; set; }
        /// <summary>
        /// 获取或设置每页大小
        /// </summary>
        /// <value>
        /// 页大小
        /// </value>
        [DataMember]
        public int PageSize { get; set; }

        /// <summary>
        /// 从JSON字符串反序列化
        /// </summary>
        /// <param name="json">JSON字符串</param>
        /// <returns></returns>
        public static SearchParameters FromJson(string json)
        {
            if (string.IsNullOrEmpty(json))
            {
                return null;
            }
            return JsonConvert.DeserializeObject<SearchParameters>(json);
        }
    }
    /// <summary>
    /// SuuchaExpression类型
    /// </summary>
    public enum SuuchaExpressionType
    {
        /// <summary>
        /// 成员表达式
        /// </summary>
        Member = 0,
        /// <summary>
        /// 常量表达式
        /// </summary>
        Constant,
        /// <summary>
        /// 逻辑与
        /// </summary>
        And,
        /// <summary>
        /// 等于
        /// </summary>
        Equal,
        /// <summary>
        /// 大于
        /// </summary>
        GreaterThan,
        /// <summary>
        /// 大于等于
        /// </summary>
        GreaterThanOrEqual,
        /// <summary>
        /// 小于
        /// </summary>
        LessThan,
        /// <summary>
        /// 小于等于
        /// </summary>
        LessThanOrEqual,
        /// <summary>
        /// 不等于
        /// </summary>
        NotEqual,
        /// <summary>
        /// 逻辑或
        /// </summary>
        Or,
        /// <summary>
        /// Like
        /// </summary>
        Like,
        /// <summary>
        /// NotLike
        /// </summary>
        NotLike,
        /// <summary>
        /// In
        /// </summary>
        In,
        /// <summary>
        /// InLike
        /// </summary>
        InLike
    }

}

